package airacrobats.io;

import airacrobats.game.Squadron;
import airacrobats.game.Stage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

/**
 * This class loads the score file.
 */
public class ScoreLoader extends DataLoader<Integer>
{
    /**
     */
    protected Integer load(DataInputStream dataInputStream) throws IOException
    {
        return dataInputStream.readInt();
    }

    /**
     * Saves the scores.
     * @param selectedSquadron The selected squadron.
     * @param stages The stages.
     */
    public void save(Squadron selectedSquadron, List<Stage> stages) throws IOException
    {
        File file = new File(selectedSquadron.getType().getPackageName() + "/dat/Scores.dat");

        DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream(file));

        for (Stage stage : stages)
            dataOutputStream.writeInt(stage.getScoreRecord());

        dataOutputStream.close();
    }
}
